package com.yidu.StockControl.controller;


import com.yidu.StockControl.entity.CashInventory;
import com.yidu.StockControl.service.CashInventoryService;
import com.yidu.Util.util.Dbutil;
import com.yidu.Util.util.TableIdUtil;
import com.yidu.Util.util.TableNameUtil;
import com.yidu.Util.util.TableTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class CashInventoryController {
    @Resource
    CashInventoryService cashInventoryService;
    @Autowired
    Dbutil dbutil;

    @RequestMapping("/selectCashInventory")
    public Map selectCashInventory(String cashInventoryTime,String businessType, int page, int limit){
        System.out.println("查询");
        List<CashInventory> list = cashInventoryService.selectCashInventory(cashInventoryTime,businessType, page, limit);
        System.out.println("list:====="+list);
        int count = cashInventoryService.selectCashInventoryCount();
        Map map = new HashMap();
        map.put("code","0");
        map.put("msg",":");
        map.put("count",count);
        map.put("data",list);
        return map;
    }


    @RequestMapping("/insertCashInventory")
    public int insertCashInventory(CashInventory cashInventory, HttpServletRequest request){
        System.out.println("插入 插入");
        HttpSession session = request.getSession();
        String fundId = (String) session.getAttribute("fundId");
        String maxId3 = dbutil.getMaxId3(TableIdUtil.CASID, TableNameUtil.CI, TableTimeUtil.CASTime, cashInventory.getCashInventoryTime());
        cashInventory.setCashInventoryId(maxId3);
        cashInventory.setFundId(fundId);
        return cashInventoryService.insertCashInventory(cashInventory);
    }

    @RequestMapping("/updateCashInventory")
    public void  updateCashInventory(CashInventory cashInventory){
        System.out.println("修改 修改");
        cashInventoryService.updateCashInventory(cashInventory);
    }

    @RequestMapping("/deleteCashInventory")
    public void deleteCashInventory(String cashInventoryId){
        System.out.println("删除 删除");
        cashInventoryService.deleteCashInventory(cashInventoryId);
    }


}
